package xiegd.study.localTime;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/3/21 15:36
 */
public class MyThread extends Thread {

    private SimpleDateFormat simpleDateFormat2;

    private DateTimeFormatter dtf;
    /* 要转换的日期字符串 */
    private String dateString;

//    public MyThread(SimpleDateFormat simpleDateFormat, String dateString) {
//        this.simpleDateFormat2 = simpleDateFormat;
//        this.dateString = dateString;
//    }

    public MyThread(DateTimeFormatter dtf, String dateString) {
        this.dtf = dtf;
        this.dateString = dateString;
    }

    @Override
    public void run() {
        try {
            //SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat simpleDateFormat = DateUtils.getSimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat simpleDateFormat2 = DateUtils.getSimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(dateString);
            String newDate = simpleDateFormat.format(date).toString();

//            LocalDate formatterDate = LocalDate.parse(dateString, dtf);
//            String format = dtf.format(formatterDate);
            if ( newDate.equals(dateString)) {
                System.out.println("ThreadName=" + this.getName()
                        + " 报错了，日期字符串：" + dateString
                        + " 转换成的日期为：" + newDate);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
